package lu.med.praxiswahl.wahlumed.service.beans;

import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.EGravDaoInt;
import lu.med.praxiswahl.wahlumed.model.beans.CustomerTBL;
import lu.med.praxiswahl.wahlumed.model.beans.EGravTBL;
import lu.med.praxiswahl.wahlumed.service.beans.serviceinterface.CustomerServiceInt;
import lu.med.praxiswahl.wahlumed.service.beans.serviceinterface.EGravServiceInt;

/**
 * Session Bean implementation class EGravService
 */
@Stateless
@Remote({ EGravServiceInt.class })
public class EGravService implements EGravServiceInt {

	@EJB
	private EGravDaoInt egravDao;
	private EGravTBL tmpEgrav;

	@EJB
	private CustomerServiceInt cust;

	/**
	 * Default constructor.
	 */
	public EGravService() {
		tmpEgrav = new EGravTBL();
	}

	@Override
	public int createEgravItem(String customer_matricule, String datum) {
		EGravTBL tmp_1 = new EGravTBL();

		tmp_1.setCustomer(cust.getCustomer(customer_matricule));
		tmp_1.setDatum(datum);

		this.egravDao.persist(tmp_1);

		return RET_OPERATION_DONE_PROPERLY;
	}

	@Override
	public EGravTBL[] getItemsByCustomer(String matricule) {
		Object[] tmp = egravDao.retrieveEgravItemsByCustomer(matricule)
				.toArray();
		EGravTBL[] eintraege = new EGravTBL[tmp.length];

		for (int i = 0; i < tmp.length; i++) {
			eintraege[i] = (EGravTBL) tmp[i];
		}
		return eintraege;
	}

	@Override
	public String get_Atd() {
		return this.tmpEgrav.getAtd();
	}

	@Override
	public String get_Bpd() {
		return this.tmpEgrav.getBpd();
	}

	@Override
	public CustomerTBL get_Customer() {
		return this.tmpEgrav.getCustomer();
	}

	@Override
	public String get_Datum() {
		return this.get_Datum();
	}

	@Override
	public String get_Fs() {
		return this.get_Fs();
	}

	@Override
	public String get_Fw() {
		return this.get_Fw();
	}

	@Override
	public String get_Heraktion() {
		return this.get_Heraktion();
	}

	@Override
	public String get_KindsBewegung() {
		return this.get_KindsBewegung();
	}

	@Override
	public String get_NUS_SSW() {
		return this.get_NUS_SSW();
	}

	@Override
	public String get_Placenta() {
		return this.get_Placenta();
	}

	@Override
	public String get_Ssl() {
		return this.get_Ssl();
	}

	@Override
	public String get_Unauffaellig() {
		return this.get_Unauffaellig();
	}

	@Override
	public int remove_EgravItem(Long egravID) {
		this.egravDao.delete(egravID);
		return RET_OPERATION_DONE_PROPERLY;
	}

	@Override
	public EGravTBL[] retrieveItemsBYINTERVAL(String fromDatum, String toDatum) {
		Object[] tmp = egravDao.getEgravItemBYINTERVAL(fromDatum, toDatum)
				.toArray();
		EGravTBL[] eintraege = new EGravTBL[tmp.length];

		for (int i = 0; i < tmp.length; i++) {
			eintraege[i] = (EGravTBL) tmp[i];
		}
		return eintraege;
	}

	@Override
	public void set_Atd(String atd) {
		this.tmpEgrav.setAtd(atd);
		this.egravDao.update(tmpEgrav);

	}

	@Override
	public void set_Bpd(String bpd) {
		this.tmpEgrav.setBpd(bpd);
		this.egravDao.update(tmpEgrav);

	}

	@Override
	public void set_Customer(CustomerTBL customer) {
		this.tmpEgrav.setCustomer(customer);
		this.egravDao.update(tmpEgrav);

	}

	@Override
	public void set_Datum(String datum) {
		this.tmpEgrav.setDatum(datum);
		this.egravDao.update(tmpEgrav);

	}

	@Override
	public void set_Fs(String fs) {
		this.tmpEgrav.setFs(fs);
		this.egravDao.update(tmpEgrav);

	}

	@Override
	public void set_Fw(String fw) {
		this.tmpEgrav.setFw(fw);
		this.egravDao.update(tmpEgrav);

	}

	@Override
	public void set_Heraktion(String heraktion) {
		this.tmpEgrav.setHerzaktion(heraktion);
		this.egravDao.update(tmpEgrav);

	}

	@Override
	public void set_KindsBewegung(String kindsBewegung) {
		this.tmpEgrav.setKindsBewegung(kindsBewegung);
		this.egravDao.update(tmpEgrav);

	}

	@Override
	public void set_NUS_SSW(String nus_ssw) {
		this.tmpEgrav.setNUS_SSW(nus_ssw);
		this.egravDao.update(tmpEgrav);

	}

	@Override
	public void set_Placenta(String placenta) {
		this.tmpEgrav.setPlacenta(placenta);
		this.egravDao.update(tmpEgrav);

	}

	@Override
	public void set_Ssl(String ssl) {
		this.tmpEgrav.setSsl(ssl);
		this.egravDao.update(tmpEgrav);

	}

	@Override
	public void set_Unauffaellig(String unauffaellig) {
		this.tmpEgrav.setUnauffaellig(unauffaellig);
		this.egravDao.update(tmpEgrav);

	}

	@Override
	public void getA_EGravInstance(EGravTBL egrav) {
		this.tmpEgrav = egrav;

	}

}
